package com.cssw.fyzb.tps.api.pay;

import com.cssw.fyzb.tps.service.pay.AliPayService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: chenchao
 * @Date: 2020/7/14 22:10
 */

@Function(description = "支付宝订单查询", parameters = {
        @Parameter(name = "tradeNo", type = Type.String, description = "流水号", required = true)
})
@Component
public class AliOrderQuery implements Action {

    private static final Logger logger = LoggerFactory.getLogger(AliOrderQuery.class);

    @Autowired
    private AliPayService ailPayService;

    @Override
    public Response execute(Request request) throws Exception {
        String tradeNo = request.getString("tradeNo");

        Map<String, String> map = ailPayService.orderQuery(tradeNo);

        logger.info(tradeNo + ">>>AliOrderQuery:" + tradeNo + ">>>" + map);
        if (map == null) {
            return Response.fail("订单支付异常");
        }

        return Response.success().put("data", map);
    }
}